//对应文件: mkfifo
#include <string.h>
#include <stdio.h>
#include <fcntl.h>	//带参数的open函数包含在内
#include <sys/types.h>
#include <sys/stat.h>	//mkfifo函数包含在内
#include <unistd.h>	
#include <stdlib.h>
#define fifo "/home/angel/bin/source/fifo"
int main(void)
{
int fd;
pid_t pid;
char message[BUFSIZ];	//BUFSIZ是指缓冲去大小
pid=mkfifo(fifo,0644);	//以prw-r-r为权限创建名为fifo的命名管道
if(pid==-1)		//源程序为if(pid=(mkfifo(fifo,0777))==-1)
{
printf(" Creat pipe failed !\n");
return 1;
}
else printf(" Creat pipe success !\n");
fd=open(fifo,O_RDWR);	//O_RDONLY: open read only; O_WRONLY: open write only; O_RDWR : read write
if(fd==-1)
{
printf("Open pipe failed !\n");
return 1;
}
if((write(fd,"Welcome to openSuSE !",22))==-1) //同pipe.c中的注释
{
printf("Write error !\n");
return 1;
}
else printf(" Write Success !\n");
if((read(fd,message,BUFSIZ))==-1)
{
printf("Read Data Error !\n");
return 1;
}
else
{
 printf(" Read Success !\n");
 printf("the Data Recived is :%s\n",message);
}
close(fd);
return 0;
}


